#include "log.h"

int printf_color(void) {
  printf("This is a character control test!\n" );
  // printf("[%2u]" CLEAR "CLEAR\n" NONE, __LINE__);

  printf("[%2u]" BLACK "BLACK " L_BLACK "L_BLACK\n" NONE, __LINE__);
  printf("[%2u]" RED "RED " L_RED "L_RED\n" NONE, __LINE__);
  printf("[%2u]" GREEN "GREEN " L_GREEN "L_GREEN\n" NONE, __LINE__);
  printf("[%2u]" BROWN "BROWN " YELLOW "YELLOW\n" NONE, __LINE__);
  printf("[%2u]" BLUE "BLUE " L_BLUE "L_BLUE\n" NONE, __LINE__);
  printf("[%2u]" PURPLE "PURPLE " L_PURPLE "L_PURPLE\n" NONE, __LINE__);
  printf("[%2u]" CYAN "CYAN " L_CYAN "L_CYAN\n" NONE, __LINE__);
  printf("[%2u]" GRAY "GRAY " WHITE "WHITE\n" NONE, __LINE__);

  printf("[%2u]\e[1;31;40m Red \e[0m\n",  __LINE__);

  printf("[%2u]" BOLD "BOLD\n" NONE, __LINE__);
  printf("[%2u]" UNDERLINE "UNDERLINE\n" NONE, __LINE__);
  printf("[%2u]" BLINK "BLINK\n" NONE, __LINE__);
  printf("[%2u]" REVERSE "REVERSE\n" NONE, __LINE__);
  printf("[%2u]" HIDE "HIDE\n" NONE, __LINE__);

  printf("Cursor test begins!\n" );
  printf("=======!\n" );
  printf("[%2u]" "\e[2ACursor up 2 lines\n" NONE, __LINE__);
  printf("[%2u]" "\e[2BCursor down 2 lines\n" NONE, __LINE__);
  printf("[%2u]" "\e[?25lCursor hide\n" NONE, __LINE__);
  printf("[%2u]" "\e[?25hCursor display\n" NONE, __LINE__);

  printf("Test ends!\n" );
  printf("[%2u]" "\e[2ACursor up 2 lines\n" NONE, __LINE__);
  printf("[%2u]" "\e[KClear from cursor downward\n" NONE, __LINE__);

  return 0;
}

void test_log() {
  UNUSED(now);
  UNUSED(tm_now);

  log_init();
  int a = 20;

  LOG_PRINT("test LOG_PRINTF %d\n", a);
  if (fopen("./lll.txt", "r") == NULL) {
    LOG_PERROR("test LOG_PERROR");
  }
  LOG_ERROR("test LOG_ERROR %d\n", a);
  LOG_WARN("test LOG_WARN %d\n", a);
  LOG_INFO("test LOG_INFO %d\n", a);
  LOG_DEBUG("test LOG_DEBUG %d\n", a);
  LOG_VERBOSE("test LOG_VERBOSE %d\n", a);

  log_deinit();
}

// void test_return1() {
// 	char *ptr = nullptr;
// 	RETURN_IF_NULL(ptr);
// }

// int test_return2() {
// 	RETURN_VAL_IF_NULL(nullptr, -1);
// }

// void test_return3() {
// 	RETURN_IF(-1);
// }

// int test_return4() {
// 	RETURN_VAL_IF(0, -1);
// }


int main(int argc, char *argv[]) {
    UNUSED(argc);
    UNUSED(argv);

    printf_color();
    enum LOG_LEVEL log_level = LOG_LEVEL_VERBOSE;
    set_log_level(log_level);
    test_log();
		// test_return1();
		// test_return2();
		// test_return3();
		// test_return4();
    return 0;
}
